package l.l.w.CodingInterviews;

/**
 * Created by llw on 2018/2/28.
 */
public class _03_1Problem {

    public boolean duplicate(int numbers[],int length,int [] duplication) {
        if(numbers == null || length < 0) return false;

        int cur;
        for(int i = 0; i < length;){
            cur = numbers[i];
            if(i == cur){
                i++;
            }else{
                if(cur == numbers[cur]){
                    duplication[0] = cur;
                    return true;
                }else{
                    numbers[i] = numbers[cur];
                    numbers[cur] = cur;
                }
            }
        }
        return false;
    }

    public static void main(String[] args) {
        int[] numbers = {2,3,1,0,2,5,3};
        int[] result = new int[1];
        boolean duplicate = new _03_1Problem().duplicate(numbers, numbers.length, result);
        System.out.println("重复？ "+ duplicate);
    }
}
